import 'package:enter_prise_web/page/index/index_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../common/constants.dart';

class SideMenuItem extends StatefulWidget {
  final List<String> titles;
  final List<IconData> icons;
  final int? itemCount;
  final Function(int index, String title)? onPress;

  const SideMenuItem(this.titles, this.icons,
      {super.key, this.onPress, this.itemCount})
      : assert(titles.length == icons.length);

  @override
  State<SideMenuItem> createState() => _SideMenuItemState();
}

class _SideMenuItemState extends State<SideMenuItem> {
  final IndexController c = Get.find();

  @override
  Widget build(BuildContext context) {
    List<Widget> createWidgets() {
      List<Widget> widgets = [];
      widgets = widget.titles.asMap().keys.map((e) {
        return InkWell(
          onTap: () {
            if (c.currentIndex.value == e) return;
            if (widget.onPress == null) return;
            widget.onPress!(e, "${widget.titles[e]}页面");
            setState(() {
              c.currentIndex.value = e;
            });
           
          },
          child: Row(
            children: [
              Expanded(
                child: Container(
                  height: 60,
                  padding: const EdgeInsets.symmetric(horizontal: 16),
                  child: Row(
                    children: [
                      Icon(
                        widget.icons[e],
                        color: (e == c.currentIndex.value)
                            ? kPrimaryColor
                            : kGrayColor,
                      ),
                      const SizedBox(
                        width: 10,
                      ),
                      Text(widget.titles[e],
                          style: TextStyle(
                              color: (c.currentIndex.value == e)
                                  ? kTextColor
                                  : kGrayColor)),
                      const Spacer(),
                    ],
                  ),
                ),
              )
            ],
          ),
        );
      }).toList();
      return widgets;
    }

    return Container(
        child: Column(
      children: createWidgets(),
    ));
  }
}
